﻿using FHJFPro.BackgroundJob.Jobs.HangfireTest;
using Hangfire;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;

namespace FHJFPro.BackgroundJob
{
   
    public static class BackgroundJobsExtensions
    {
        public static void UseHangfireTest(this IServiceProvider service)
        {
            var job = service.GetService<HangfireTestJob>();
            RecurringJob.AddOrUpdate("定时任务测试", () => job.ExecuteAsync(), CronType.Minute());
        }
        public static void UseHangfireTest2(this IServiceProvider service)
        {
            var job = service.GetService<HangfireTestJob>();
            RecurringJob.AddOrUpdate("定时任务测试2", () => job.ExecuteAsync2(), CronType.Minute());
        }
    }

    public static class UseBackgroundJobs
    {
        /// <summary>
        /// 激活执行job
        /// </summary>
        public static void UseExcuteSchedulingTask(this IApplicationBuilder app)
        {
            var service = app.ApplicationServices;
            service.UseHangfireTest();
            service.UseHangfireTest2();

        }
    }
}
